<?php
// +----------------------------------------------------------------------
// | YZCMS <XueHen CMS>
// +----------------------------------------------------------------------
// | Copyright (c) http://www.yingzhengwangluo.com
// +----------------------------------------------------------------------
// | Author XueHen <490860758@qq.com>
// +----------------------------------------------------------------------
namespace Home\Controller;

class ContentController extends BaseController {
    function index(){
	    $id = I('get.id');
		$db = M('content');
		if(preg_match("/[0-9]+/",$id)){
			$result = $db->where(array('id'=>$id))->find();
		}else{
			$result = $db->where("url = '$id'")->find();
		}
		if(empty($result)){
			show_404_error();
			exit;
		}
		
		$result['hit'] = $hit = $result['hit'] + 1;
		$this->assign('content',$result);
		$db->save(array('id'=>$result['id'],'hit'=>$hit));
		//获取评论
		$db = M('book');
		$this->bcount = $db->where(array('cid'=>$result['id'],'type'=>'article'))->count();
		$this->book = $db->where(array('cid'=>$result['id'],'type'=>'article'))->select();		
		$this->display();
		
    }
}